package com.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.reggie.common.BaseContext;
import com.reggie.entity.AddressBook;
import com.reggie.mapper.AddressBookMapper;
import com.reggie.service.AddressBookService;
import org.springframework.stereotype.Service;

@Service
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {
    /**
     * 设置默认地址
     * @param id
     */
    public AddressBook setdefault(Long id) {
        LambdaUpdateWrapper<AddressBook> luq = new LambdaUpdateWrapper<>();
        luq.eq(AddressBook::getUserId,BaseContext.getCurrentId());
        luq.set(AddressBook::getIsDefault,0);
        super.update(luq);

        AddressBook addressBook = new AddressBook();
        addressBook.setId(id);
        addressBook.setIsDefault(1);
        super.updateById(addressBook);
        return addressBook;
    }
}
